import {request} from '../../network/index'
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		active:0,
		radio: '内地',
		newMVData:[],
		limit:3,
		limit1:3,
		offset:0,
		offset1:0,
		offset2:0,
		type:'',
		two:[],
		toplist:[],
		allData:[],
		select:''
	},
	async select(event){
		console.log(event.detail);

		let newMV = await request('/mv/first',{limit:this.data.limit,area:event.detail})
		this.setData({
			type:event.detail,
			newMVData:newMV.data.data
		})
	},
	//请求最新数据
	async getNewMv(num,type){
			let newMV = await request('/mv/first',{limit:num,area:type})
			let arr = newMV.data.data.slice(this.data.limit-3,this.data.limit)
			this.data.newMVData.push(...arr)
			this.setData({
				newMVData:this.data.newMVData
			})
	},
		async onChange(event){
		this.setData({
			active:event.detail.name
		})
		if(event.detail.name === 1){
			let two = await request('/mv/exclusive/rcmd',{limit:3})
			console.log(two);
				this.setData({
					two:two.data.data
				})
		}else if(event.detail.name === 2){
			
			let toplist = await request('/top/mv',{limit:6})
			console.log(toplist);
			this.setData({
				toplist:toplist.data.data
			})
		}else if(event.detail.name === 3){
			let allData = await request('/mv/all',{limit:8})
			
			this.setData({
				allData:allData.data.data
			})
		}
	},
	toPlay(event){
		let id = event.currentTarget.dataset.id
		wx.navigateTo({
			url: `/pages/mvPlay/mvPlay?id=${id}`,
		})
	},
	//mv刷选
	async onChange1(event) {
    this.setData({
      radio: event.detail,
		});
		
	let toplist = await request('/top/mv',{limit:6,area:this.data.radio})
	this.setData({
		toplist:toplist.data.data
	})
	},
	//全部MV
	async change(event){
		console.log(event.detail);
		this.data.select = event.detail
		let allData = await request('/mv/all',{limit:8,...event.detail})
		this.setData({
			allData:allData.data.data
		})
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad:async function (options) {
		this.getNewMv(this.data.limit,this.data.type)
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom:async function () {
		console.log(this.data.active);
		if(this.data.active === 0){
			this.data.limit+=3
			this.getNewMv(this.data.limit,this.data.type)
		}else if(this.data.active === 1){
			this.data.offset +=3
			let two = await request('/mv/exclusive/rcmd',{limit:3,offset:this.data.offset})
			this.data.two.push(...two.data.data)
				this.setData({
					two:this.data.two
				})
		}else if(this.data.active === 2){
			this.data.offset1 += 6
			let toplist = await request('/top/mv',{limit:6,offset:this.data.offset1,area:this.data.radio})
			this.data.toplist.push(...toplist.data.data)
			this.setData({
				toplist:this.data.toplist
			})
		}else if(this.data.active === 3){
			this.data.offset2 += 8
			let allData = await request('/mv/all',{limit:8,offset:this.data.offset2,...this.data.select})
			this.data.allData.push(...allData.data.data)
			this.setData({
				allData:this.data.allData
			})
		}
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})